<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class Tastreet extends CI_Controller {
	
	function __construct() {
		parent::__construct ();
	
	}
	
	public function index() {
		
		$id = (int)$this->uri->segment(2);
		if(!isset($id) || $id == ''){
			$this->load->view('error');
			return ;
		}
		//该会员的信息
		$this->db->select('*');
		$this->db->from('member');
		$this->db->where('id',$id);
		$eData['tamember'] = $this->db->get()->row_array();
		
		$ePage = ( int ) $this->input->get ('page' );
		$this->db->select('street.*,codevalue.value as areaname');
		$this->db->from('street');
		$this->db->join('livestreet','livestreet.street=street.id');
		$this->db->join('codevalue','codevalue.code=street.area');
		$this->db->where('livestreet.member',$id);
		$this->db->where('codevalue.name','area');
		$this->db->limit(10,$ePage);
		$eData['streetList'] = $this->db->get()->result_array();
		//他居住的街道数目
		$this->db->where('member',$id);
		$eData ['liveCount'] = $this->db->count_all_results( 'livestreet' );
		//他添加的街道数目
		$this->db->where('createid',$id);
		$eData ['addCount'] = $this->db->count_all_results( 'street' );
//		他管理的街道数目		
		$this->db->where('manager',$id);
		$eData ['managerCount'] = $this->db->count_all_results( 'street' );
		//他的评论的街道数目
		$this->db->select('count(DISTINCT belongId) as commentCount');
		$this->db->from('comment');
		$this->db->where('type',1);
		$this->db->where('creatid',$id);
		$commentCount = $this->db->get()->row_array();
		$eData ['commentCount'] = $commentCount['commentCount'];
		
		$eData['streetListCount'] = $eData ['liveCount'];
		$this->load->library ( 'pagination' );
		$eConfig ['per_page'] = 10;
		$eConfig ['num_links'] = 5;
		$eConfig ['base_url'] = site_url ( 'tastreet/'.$id.'?1=1');
		$eConfig ['total_rows'] = $eData ['streetListCount'];
		$eConfig ['first_link'] = false;
		$eConfig ['last_link'] = false;
		$eConfig ['next_link'] = '下一页';
		$eConfig ['next_tag_open'] = '<li>';
		$eConfig ['next_tag_close'] = '</li>';
		$eConfig ['prev_link'] = '上一页';
		$eConfig ['prev_tag_open'] = '<li>';
		$eConfig ['prev_tag_close'] = '</li>';
		$eConfig ['num_tag_open'] = '<li>';
		$eConfig ['num_tag_close'] = '</li>';
		$eConfig ['cur_tag_open'] = '<li class="current"><a href="#">';
		$eConfig ['cur_tag_close'] = '</a></li>';
		$this->pagination->initialize ( $eConfig );
		
		$this->load->view('tastreet',$eData);
	}
	
	function add(){
		$id = (int)$this->uri->segment(3);
		if(!isset($id) || $id == ''){
			$this->load->view('error');
			return ;
		}
		//该会员的信息
		$this->db->select('*');
		$this->db->from('member');
		$this->db->where('id',$id);
		$eData['tamember'] = $this->db->get()->row_array();
		
		$ePage = ( int ) $this->input->get ('page' );
		$this->db->select('street.*,codevalue.value as areaname');
		$this->db->from('street');
		$this->db->join('codevalue','codevalue.code=street.area');
		$this->db->where('street.createid',$id);
		$this->db->where('codevalue.name','area');
		$this->db->limit(10,$ePage);
		$eData['streetList'] = $this->db->get()->result_array();
		
		//他居住的街道数目
		$this->db->where('member',$id);
		$eData ['liveCount'] = $this->db->count_all_results( 'livestreet' );
		//他添加的街道数目
		$this->db->where('createid',$id);
		$eData ['addCount'] = $this->db->count_all_results( 'street' );
		$eData['streetListCount'] = $eData ['addCount'];
//		他管理的街道数目		
		$this->db->where('manager',$id);
		$eData ['managerCount'] = $this->db->count_all_results( 'street' );
		//他的评论的街道数目
		$this->db->select('count(DISTINCT belongId) as commentCount');
		$this->db->from('comment');
		$this->db->where('type',1);
		$this->db->where('creatid',$id);
		$commentCount = $this->db->get()->row_array();
		$eData ['commentCount'] = $commentCount['commentCount'];
		
		
		$this->load->library ( 'pagination' );
		$eConfig ['per_page'] = 10;
		$eConfig ['num_links'] = 5;
		$eConfig ['base_url'] = site_url ( 'tastreet/add/'.$id.'?1=1');
		$eConfig ['total_rows'] = $eData ['streetListCount'];
		$eConfig ['first_link'] = false;
		$eConfig ['last_link'] = false;
		$eConfig ['next_link'] = '下一页';
		$eConfig ['next_tag_open'] = '<li>';
		$eConfig ['next_tag_close'] = '</li>';
		$eConfig ['prev_link'] = '上一页';
		$eConfig ['prev_tag_open'] = '<li>';
		$eConfig ['prev_tag_close'] = '</li>';
		$eConfig ['num_tag_open'] = '<li>';
		$eConfig ['num_tag_close'] = '</li>';
		$eConfig ['cur_tag_open'] = '<li class="current"><a href="#">';
		$eConfig ['cur_tag_close'] = '</a></li>';
		$this->pagination->initialize ( $eConfig );
		
		$this->load->view('tastreetadd',$eData);
	}
	
	function mang(){
		$id = (int)$this->uri->segment(3);
		if(!isset($id) || $id == ''){
			$this->load->view('error');
			return ;
		}
		//该会员的信息
		$this->db->select('*');
		$this->db->from('member');
		$this->db->where('id',$id);
		$eData['tamember'] = $this->db->get()->row_array();
		
		$ePage = ( int ) $this->input->get ('page' );
		$this->db->select('street.*,codevalue.value as areaname');
		$this->db->from('street');
		$this->db->join('codevalue','codevalue.code=street.area');
		$this->db->where('street.manager',$id);
		$this->db->where('codevalue.name','area');
		$this->db->limit(10,$ePage);
		$eData['streetList'] = $this->db->get()->result_array();
		
		//他居住的街道数目
		$this->db->where('member',$id);
		$eData ['liveCount'] = $this->db->count_all_results( 'livestreet' );
		//他添加的街道数目
		$this->db->where('createid',$id);
		$eData ['addCount'] = $this->db->count_all_results( 'street' );
//		他管理的街道数目		
		$this->db->where('manager',$id);
		$eData ['managerCount'] = $this->db->count_all_results( 'street' );
		$eData['streetListCount'] = $eData ['managerCount'];
		//他的评论的街道数目
		$this->db->select('count(DISTINCT belongId) as commentCount');
		$this->db->from('comment');
		$this->db->where('type',1);
		$this->db->where('creatid',$id);
		$commentCount = $this->db->get()->row_array();
		$eData ['commentCount'] = $commentCount['commentCount'];
		
		
		$this->load->library ( 'pagination' );
		$eConfig ['per_page'] = 10;
		$eConfig ['num_links'] = 5;
		$eConfig ['base_url'] = site_url ( 'tastreet/mang/'.$id.'?1=1');
		$eConfig ['total_rows'] = $eData ['streetListCount'];
		$eConfig ['first_link'] = false;
		$eConfig ['last_link'] = false;
		$eConfig ['next_link'] = '下一页';
		$eConfig ['next_tag_open'] = '<li>';
		$eConfig ['next_tag_close'] = '</li>';
		$eConfig ['prev_link'] = '上一页';
		$eConfig ['prev_tag_open'] = '<li>';
		$eConfig ['prev_tag_close'] = '</li>';
		$eConfig ['num_tag_open'] = '<li>';
		$eConfig ['num_tag_close'] = '</li>';
		$eConfig ['cur_tag_open'] = '<li class="current"><a href="#">';
		$eConfig ['cur_tag_close'] = '</a></li>';
		$this->pagination->initialize ( $eConfig );
		
		$this->load->view('tastreetmang',$eData);
	}
	
	function comment(){
		$id = (int)$this->uri->segment(3);
		if(!isset($id) || $id == ''){
			$this->load->view('error');
			return ;
		}
		//该会员的信息
		$this->db->select('*');
		$this->db->from('member');
		$this->db->where('id',$id);
		$eData['tamember'] = $this->db->get()->row_array();
		
		$ePage = ( int ) $this->input->get ('page' );
		$this->db->distinct();
		$this->db->select('street.*,codevalue.value as areaname');
		$this->db->from('street');
		$this->db->join('codevalue','codevalue.code=street.area');
		$this->db->join('comment','comment.belongId=street.id');
		$this->db->where('comment.type',1);
		$this->db->where('comment.creatid',$id);
		$this->db->where('codevalue.name','area');
		$this->db->limit(10,$ePage);
		$eData['streetList'] = $this->db->get()->result_array();
		//他居住的街道数目
		$this->db->where('member',$id);
		$eData ['liveCount'] = $this->db->count_all_results( 'livestreet' );
		//他添加的街道数目
		$this->db->where('createid',$id);
		$eData ['addCount'] = $this->db->count_all_results( 'street' );
//		他管理的街道数目		
		$this->db->where('manager',$id);
		$eData ['managerCount'] = $this->db->count_all_results( 'street' );
		//他的评论的街道数目
		$this->db->select('count(DISTINCT belongId) as commentCount');
		$this->db->from('comment');
		$this->db->where('type',1);
		$this->db->where('creatid',$id);
		$commentCount = $this->db->get()->row_array();
		$eData ['commentCount'] = $commentCount['commentCount'];
		
		$eData['streetListCount'] = $eData ['commentCount'];
		$this->load->library ( 'pagination' );
		$eConfig ['per_page'] = 10;
		$eConfig ['num_links'] = 5;
		$eConfig ['base_url'] = site_url ( 'tastreet/comment/'.$id.'?1=1');
		$eConfig ['total_rows'] = $eData ['streetListCount'];
		$eConfig ['first_link'] = false;
		$eConfig ['last_link'] = false;
		$eConfig ['next_link'] = '下一页';
		$eConfig ['next_tag_open'] = '<li>';
		$eConfig ['next_tag_close'] = '</li>';
		$eConfig ['prev_link'] = '上一页';
		$eConfig ['prev_tag_open'] = '<li>';
		$eConfig ['prev_tag_close'] = '</li>';
		$eConfig ['num_tag_open'] = '<li>';
		$eConfig ['num_tag_close'] = '</li>';
		$eConfig ['cur_tag_open'] = '<li class="current"><a href="#">';
		$eConfig ['cur_tag_close'] = '</a></li>';
		$this->pagination->initialize ( $eConfig );
		
		$this->load->view('tastreetcomment',$eData);
	}
}

